package net.wanho.shop.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * Ajax响应结果对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class R implements Serializable {
    // 响应状态码
    private Integer code;

    // 响应消息
    private String msg;

    // 响应数据
    private Object data;

    public static R success(Integer code, String msg, Object data){
        return new R(code, msg, data);
    }

    public static R success(Integer code, String msg){
        return new R(code, msg, null);
    }

    public static R success(Object data){
        return new R(200, "success", data);
    }

    public static R success(String msg){
        return new R(200, msg, null);
    }

    public static R fail(Integer code, String msg){
        return new R(code, msg, null);
    }

    public static R fail(String msg){
        return new R(500, msg, null);
    }
}
